const { User } = require('../../model/user');
const pagination = require('mongoose-sex-page');
module.exports = async (req,res)=>{
  //两个都有选项
  if (req.body.role != 'all' && req.body.state != 2){
    let page = req.query.page;
    let users = await pagination(User).find({role: req.body.role,state: req.body.state}).page(page).size(5).display(3).exec();
    res.render('admin/userList',{
      users
    });
  }
  //角色有，状态没有
  else if (req.body.role != 'all' && req.body.state == 2){
    let page = req.query.page;
    let users = await pagination(User).find({role: req.body.role}).page(page).size(5).display(3).exec();
    res.render('admin/userList',{
      users
    });
  }
  //角色没有，状态有
  else if (req.body.role == 'all' && req.body.state !=2 ){
    let page = req.query.page;
    let users = await pagination(User).find({state: req.body.state}).page(page).size(5).display(3).exec();
    res.render('admin/userList',{
      users
    });
  }
  //两个都没有
  else{
    let page = req.query.page;
    let users = await pagination(User).find().page(page).size(5).display(3).exec();
    res.render('admin/userList',{
      users
    });
  }
}